<template name="basics">
	<view class="content">
		<cu-custom bgColor="bg-blue"><block slot="content">猎阵生物</block></cu-custom>
		<swiper class="screen-swiper round-dot" :indicator-dots="true" :circular="true"
		 :autoplay="true" interval="5000" duration="500">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<image :src="item.url" mode="aspectFill" v-if="item.type=='image'"></image>
				<video :src="item.url" autoplay loop muted :show-play-btn="false" :controls="false" objectFit="cover" v-if="item.type=='video'"></video>
			</swiper-item>
		</swiper>
		<view class="cu-list grid col-4 no-border">
			<view class="cu-item" @click="goAdvertisingList(2)">
				<view class="cuIcon-flashlightclose text-yellow">
				</view>
				<text>服务说明</text>
			</view>
			<view class="cu-item" @click="goTestReport">
				<view class="cuIcon-newshot text-orange">
				</view>
				<text>历史报告</text>
			</view>
			<view class="cu-item" @click="goAuth">
				<view class="cuIcon-favorfill text-yellow">
				</view>
				<text>会员注册</text>
			</view>
			<view class="cu-item" @click="goAdvertisingList(1)">
				<view class="cuIcon-attentionfill text-cyan">
				</view>
				<text>农业部认证</text>
			</view>
		</view>
		<view class="cu-bar bg-white solid-bottom">
			<view class='action text-bold'>
				服务分类
			</view>
		</view>
		<scroll-view scroll-y class="basic-scroll-margin-bottom margin-bottom-xl padding-bottom-xl">
			<view class="grid margin-bottom text-center col-2">
				<view class="cu-card case"  @click="goTestAdd(simpleType.value,simpleType.label)" v-for="(simpleType,index) in simpleTypeList" :key="index">
					<view class="cu-item shadow">
						<view class="image">
							<image :src="simpleType.cover?simpleType.cover:'http://pt.huntarray.com/profile/upload/2020/01/16/ff8bdcd26eef305d210da1773e15fa2e.png'"
							 mode="widthFix"></image>
						</view>
						<text class="text-cut">{{simpleType.label}}</text>
					</view>
				</view>
				<view class="cu-card case"  @click="goAdvertisingList(3)">
					<view class="cu-item shadow">
						<view class="image">
							<image src="http://pt.huntarray.com/profile/upload/2020/01/16/59b5faab35bde5b3cb33bda51bb05dc4.png"
							 mode="widthFix"></image>
						</view>
						<text class="text-cut">猎弧一号—弧菌克星</text>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	
	import { listSimpleType } from '../../../api/modules/simpleTypeApi.js'
	import { listSimpleAdvertising } from '../../../api/modules/simpleAdvertising.js'
	export default {
		name: "basics",
		props:{
			showState: {
			  // 页面重新显示
			  type: Number,
			  default: 1
			}
		},
		data() {
			return {
				swiperList:[{id:0,url:"http://pt.huntarray.com/profile/upload/2020/01/16/ff8bdcd26eef305d210da1773e15fa2e.png",type:"image"},
				],
				pageNum:1,
				pageSize:10,
				simpleTypeList:uni.getStorageSync("simpleTypeList")?uni.getStorageSync("simpleTypeList"):[]
			};
		},
		watch:{
			showState(){
				let self=this
				if(self.simpleTypeList.length==0){
					this.getList()
				}
			}
		},
		onReady(){
			this.getList()
			this.getSimpleAdvertisingList()
		}
		,
		methods: {
			getList(){
				let self=this
				let data={pageNum:self.pageNum,pageSize:self.pageSize,delFlag:0}
				listSimpleType(data).then(res=>{
					let simpleTypeList=res.data.rows
					let simpleTypeSelectors=[]
					for(let index in simpleTypeList){
						simpleTypeSelectors.push({
							label:simpleTypeList[index].simpleTypeName,
							value:simpleTypeList[index].simpleTypeId,
							cover:simpleTypeList[index].simpleTypeCover
						})
					}
					self.simpleTypeList=simpleTypeSelectors
					uni.setStorageSync("simpleTypeList",simpleTypeSelectors)
				})
			},
			getSimpleAdvertisingList(){
				let data={pageNum:1,pageSize:10,type:0,delFlag:0}
				listSimpleAdvertising(data).then(res=>{
					if(res.data.code==200){
						this.swiperList=[]
						let swiperList=res.data.rows
						let swiperListSelectors=[]
						for(let index in swiperList){
							swiperListSelectors.push({
								url:swiperList[index].cover,
								id:swiperList[index].advertising_id,
								type:"image"
							})
						}
						if(swiperListSelectors.length>0){
							this.swiperList=swiperListSelectors
						}
					}
				})
			},
			goTestAdd(simpleTypeId,simpleTypeName){
				uni.navigateTo({
					url: '/pages/add/home?simpleTypeId='+simpleTypeId+"&simpleTypeName="+simpleTypeName
				});
			},
			goAdvertisingList(type){
				uni.navigateTo({
					url:"/pages/basics/advertisingList/advertisingList?type="+type
				});
			},
			goTestAddNomal(){
				uni.navigateTo({
					url: '/pages/add/home'
				});
			},
			goTestReport(){
				uni.navigateTo({
					url: '/pages/basics/orderList/orderList'
				});
			},
			goAuth(){
				uni.navigateTo({
					url:"/pages/mine/auth/auth"
				})
			}
		}
	}
</script>

<style>
	
</style>
